//////////////////////////////////////////////////////////////////////////////////
//	File Name:	ObjectFactory.h
//	Author	 :	Yuri Oyoko
//	Purpose	 :	The object factory contains function pointers for creating
//				game objects
//////////////////////////////////////////////////////////////////////////////////

#pragma once

//Includes
#include <map>
using std::map;

template <typename ClassIDType, typename BaseClassType>
class ObjectFactory
{
private:
	typedef BaseClassType* (*ObjectCreator)(void);
	map<ClassIDType, ObjectCreator> ObjectCreators;

	static ObjectFactory<ClassIDType, BaseClassType> Instance;

	ObjectFactory(){}
	ObjectFactory(const ObjectFactory&);
	ObjectFactory& operator=(const ObjectFactory&);
	~ObjectFactory(){}

	template<typename DerivedClassType>
	static BaseClassType* ConstructObject()
	{
		return new DerivedClassType;
	}
public:
	static ObjectFactory<ClassIDType, BaseClassType>* GetInstance()
	{
		return Instance;
	}
	template<typename DerivedClassType>
	bool RegisterClassType(ClassIDType ID)
	{
		std::pair<ClassIDType, ObjectCreator> ObjectTypeDef;
		ObjectTypeDef.first = ID;
		ObjectTypeDef.second = ConstructObject<DerivedClassType>;

		ObjectCreators.insert(ObjectTypeDef);
		return true
	}
	bool UnregisterClassType(ClassIDType ID)
	{
		map<ClassIDType, ObjectCreator>::iterator theIterator = ObjectCreators.find(ID);

		if(theIterator == ObjectCreators.end())
			return false;

		ObjectCreators.erase(theIterator);
		return true;
	}
	void ShutdownObjectFactory()
	{
		ObjectCreators.clear();
	}
};

template<typename ClassIDType, typename BaseClassType>
ObjectFactory<ClassIDType, BaseClassType>
ObjectFactory<ClassIDType, BaseClassType>::Instance;